package com.jdd.modules.sentrybox.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jdd.common.api.vo.Result;
import com.jdd.common.aspect.annotation.AutoLog;
import com.jdd.common.constant.JddConstant;
import com.jdd.common.util.CarColorEnum;
import com.jdd.common.util.DateUtil;
import com.jdd.common.util.DateUtils;
import com.jdd.modules.order.entity.ParkOrderInfo;
import com.jdd.modules.order.service.IParkOrderInfoService;
import com.jdd.modules.parkcar.entity.ParkCarMonthly;
import com.jdd.modules.parkcar.service.IParkCarMonthlyService;
import com.jdd.modules.parking.entity.InParkinglotCar;
import com.jdd.modules.parking.entity.ParkCarEnterLog;
import com.jdd.modules.parking.entity.ParkCarOutLog;
import com.jdd.modules.parking.service.IInParkinglotCarService;
import com.jdd.modules.parking.service.IparkCarEnterLogService;
import com.jdd.modules.parking.service.IparkCarOutLogService;
import com.jdd.modules.parkmonthly.dto.MonthlyCardInfoDTO;
import com.jdd.modules.parkmonthly.entity.MonthlyCarConfig;
import com.jdd.modules.parkmonthly.entity.MonthlyCardInfo;
import com.jdd.modules.parkmonthly.service.IMonthlyCarConfigService;
import com.jdd.modules.parkmonthly.service.IMonthlyCardInfoService;
import com.jdd.modules.parkmonthly.service.IMonthlyDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @Description: 车场车辆记录查询控制器
 * @author: ZhuLiuWei
 * @date: 2022/2/15 11:31
 */
@Slf4j
@RestController
@RequestMapping("/sentryBox/parkCarRecord")
@Api(tags = "车场车辆记录查询")
public class ParkCarRecordController {

    @Resource
    private IparkCarEnterLogService parkCarEnterLogService;
    @Resource
    private IparkCarOutLogService parkCarOutLogService;
    @Resource
    private IParkOrderInfoService parkOrderInfoService;
    @Resource
    private IMonthlyCardInfoService monthlyCardInfoService;
    @Resource
    private IParkCarMonthlyService parkCarMonthlyService;
    @Resource
    private IMonthlyCarConfigService monthlyCarConfigService;
    @Resource
    private IMonthlyDepartmentService monthlyDepartmentService;
    @Resource
    private IInParkinglotCarService parkCarInfoService;

    /**
     * 新岗亭车辆入场记录
     *
     * @param parkCarEnterLog 查询入参
     * @param pageNo          页码
     * @param pageSize        每页条数
     * @param timeStart       入场开始时间
     * @param timeEnd         入场结束时间
     * @return 入场记录列表
     */
    @AutoLog(value = "新岗亭车辆入场记录-分页列表查询")
    @ApiOperation(value = "新岗亭车辆入场记录-分页列表查询", notes = "新岗亭车辆入场记录-分页列表查询")
    @GetMapping(value = "/parkCarEnterLogList")
    public Result<IPage<ParkCarEnterLog>> parkCarEnterLogList(ParkCarEnterLog parkCarEnterLog,
                                                              @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                              @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                              @RequestParam(name = "timeStart", required = false) String timeStart,
                                                              @RequestParam(name = "timeEnd", required = false) String timeEnd) {
        Result<IPage<ParkCarEnterLog>> result = new Result<>();
        LambdaQueryWrapper<ParkCarEnterLog> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtils.isNotEmpty(parkCarEnterLog)) {
            //车牌号
            if (StringUtils.isNotEmpty(parkCarEnterLog.getPlateNo())) {
                queryWrapper.like(ParkCarEnterLog::getPlateNo, parkCarEnterLog.getPlateNo());
            }
            //入场地点
            if (StringUtils.isNotEmpty(parkCarEnterLog.getArmName())) {
                queryWrapper.eq(ParkCarEnterLog::getArmName, parkCarEnterLog.getArmName());
            }
            //设备序列号
            if (StringUtils.isNotEmpty(parkCarEnterLog.getSerialNo())) {
                queryWrapper.eq(ParkCarEnterLog::getSerialNo, parkCarEnterLog.getSerialNo());
            }
            //入场类型：0：默认 1：重复入场 2：手动入场 3：补录入场
            if (ObjectUtils.isNotEmpty(parkCarEnterLog.getEnterType())) {
                queryWrapper.eq(ParkCarEnterLog::getEnterType, parkCarEnterLog.getEnterType());
            }
            //车辆状态 0: 在场 1:已出场
            if (StringUtils.isNotEmpty(parkCarEnterLog.getIsOut())) {
                queryWrapper.eq(ParkCarEnterLog::getIsOut, parkCarEnterLog.getIsOut());
            }
        }

        //入场时间
        if (StringUtils.isNotEmpty(timeStart)) {
            queryWrapper.ge(ParkCarEnterLog::getCarEnterTime, timeStart);
        }
        if (StringUtils.isNotEmpty(timeEnd)) {
            queryWrapper.le(ParkCarEnterLog::getCarEnterTime, timeEnd);
        }
        queryWrapper.ne(ParkCarEnterLog::getIsTransfer, JddConstant.StringNumber.STRING_ONE);
        queryWrapper.orderByDesc(ParkCarEnterLog::getCarEnterTime);
        Page<ParkCarEnterLog> page = new Page<>(pageNo, pageSize);
        IPage<ParkCarEnterLog> pageList = parkCarEnterLogService.page(page, queryWrapper);
        List<ParkCarEnterLog> records = pageList.getRecords();
        if (null != records) {
            records.forEach(item -> {
                if (StringUtils.isEmpty(item.getCarTypeName()) && JddConstant.MqttRecResultPushLog.IS_WHITE_ZERO.equals(item.getCarNature())) {
                    item.setCarTypeName(JddConstant.VehicleType.TEMPORARYCAR);
                }
            });
        }
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 新岗亭车辆出场信息
     *
     * @param parkCarOutLog 查询入参
     * @param pageNo        页码
     * @param pageSize      每页条数
     * @param timeStart     出场开始时间
     * @param timeEnd       出场结束时间
     * @return 出场信息列表
     */
    @AutoLog(value = "新岗亭车辆出场信息-分页列表查询")
    @ApiOperation(value = "新岗亭车辆出场信息-分页列表查询", notes = "新岗亭车辆出场信息-分页列表查询")
    @GetMapping(value = "/parkCarOutLogList")
    public Result<IPage<ParkCarOutLog>> parkCarOutLogList(ParkCarOutLog parkCarOutLog,
                                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                          @RequestParam(name = "timeStart", required = false) String timeStart,
                                                          @RequestParam(name = "timeEnd", required = false) String timeEnd) {
        Result<IPage<ParkCarOutLog>> result = new Result<>();
        LambdaQueryWrapper<ParkCarOutLog> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtils.isNotEmpty(parkCarOutLog)) {
            //车牌号
            if (StringUtils.isNotEmpty(parkCarOutLog.getPlateNo())) {
                queryWrapper.like(ParkCarOutLog::getPlateNo, parkCarOutLog.getPlateNo());
            }
            //出场地点
            if (StringUtils.isNotEmpty(parkCarOutLog.getArmName())) {
                queryWrapper.eq(ParkCarOutLog::getArmName, parkCarOutLog.getArmName());
            }
            //设备序列号
            if (StringUtils.isNotEmpty(parkCarOutLog.getSerialNo())) {
                queryWrapper.eq(ParkCarOutLog::getSerialNo, parkCarOutLog.getSerialNo());
            }
            //出场类型 1 : 正常出场 2：手动出场 3：补录场内
            if (ObjectUtils.isNotEmpty(parkCarOutLog.getOuterType())) {
                if (JddConstant.IntNumber.INT_TWO == parkCarOutLog.getOuterType()) {
                    queryWrapper.eq(ParkCarOutLog::getOuterType, JddConstant.IntNumber.INT_TWO);
                } else if (JddConstant.IntNumber.INT_THREE == parkCarOutLog.getOuterType()) {
                    queryWrapper.eq(ParkCarOutLog::getOuterType, JddConstant.IntNumber.INT_THREE);
                }
            }
        }
        //出场时间
        if (StringUtils.isNotEmpty(timeStart)) {
            queryWrapper.ge(ParkCarOutLog::getCarOutTime, timeStart);
        }
        if (StringUtils.isNotEmpty(timeEnd)) {
            queryWrapper.le(ParkCarOutLog::getCarOutTime, timeEnd);
        }
        queryWrapper.orderByDesc(ParkCarOutLog::getCreateTime);
        Page<ParkCarOutLog> page = new Page<>(pageNo, pageSize);
        IPage<ParkCarOutLog> pageList = parkCarOutLogService.page(page, queryWrapper);
        List<ParkCarOutLog> records = pageList.getRecords();
        if (null != records) {
            records.forEach(item -> {
                if (item.getOuterType() == null) {
                    item.setOuterType(JddConstant.IntNumber.INT_ONE);
                }
                if (StringUtils.isNotEmpty(item.getCarEnterId())) {
                    ParkCarEnterLog carEnterLog = parkCarEnterLogService.getById(item.getCarEnterId());
                    if (carEnterLog != null) {
                        item.setCarTypeName(carEnterLog.getCarTypeName());
                    }
                }
                if (StringUtils.isEmpty(item.getCarTypeName()) && JddConstant.MqttRecResultPushLog.IS_WHITE_ZERO.equals(item.getCarNature())) {
                    item.setCarTypeName(JddConstant.VehicleType.TEMPORARYCAR);
                }
            });
        }
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 新岗亭车辆停车记录信息
     *
     * @param parkOrderInfo 查询入参
     * @param pageNo        页码
     * @param pageSize      每页条数
     * @param timeStart     出场开始时间
     * @param timeEnd       出场结束时间
     * @return 停车记录信息列表
     */
    @ApiOperation(value = "新岗亭车辆停车记录信息-分页列表查询", notes = "新岗亭车辆停车记录信息-分页列表查询")
    @GetMapping(value = "/parkCarOrderList")
    public Result<IPage<ParkOrderInfo>> parkCarOrderList(ParkOrderInfo parkOrderInfo,
                                                         @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                         @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                         @RequestParam(name = "timeStart", required = false) String timeStart,
                                                         @RequestParam(name = "timeEnd", required = false) String timeEnd) {
        Result<IPage<ParkOrderInfo>> result = new Result<>();

        LambdaQueryWrapper<ParkOrderInfo> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtils.isNotEmpty(parkOrderInfo)) {
            //车牌号
            if (StringUtils.isNotEmpty(parkOrderInfo.getPlateNo())) {
                queryWrapper.like(ParkOrderInfo::getPlateNo, parkOrderInfo.getPlateNo());
            }
            //出场地点
            if (StringUtils.isNotEmpty(parkOrderInfo.getArmName())) {
                queryWrapper.eq(ParkOrderInfo::getArmName, parkOrderInfo.getArmName());
            }
            //设备序列号
            if (StringUtils.isNotEmpty(parkOrderInfo.getSerialNo())) {
                queryWrapper.eq(ParkOrderInfo::getSerialNo, parkOrderInfo.getSerialNo());
            }
        }
        //出场时间
        if (StringUtils.isNotEmpty(timeStart)) {
            queryWrapper.ge(ParkOrderInfo::getOutTime, timeStart);
        }
        if (StringUtils.isNotEmpty(timeEnd)) {
            queryWrapper.le(ParkOrderInfo::getOutTime, timeEnd);
        }
        Page<ParkOrderInfo> page = new Page<>(pageNo, pageSize);
        queryWrapper.eq(ParkOrderInfo::getOrderStatus, JddConstant.StringNumber.STRING_TWO);
        queryWrapper.orderByDesc(ParkOrderInfo::getEnterTime);
        IPage<ParkOrderInfo> pageList = parkOrderInfoService.page(page, queryWrapper);
        List<ParkOrderInfo> records = pageList.getRecords();
        if (null != records) {
            records.forEach(item -> {
                if (StringUtils.isNotEmpty(item.getCarEnterId())) {
                    ParkCarEnterLog carEnterLog = parkCarEnterLogService.getById(item.getCarEnterId());
                    if (carEnterLog != null) {
                        //停车场入口名称
                        item.setEnterArmName(carEnterLog.getArmName());
                        //车辆性质(0:临时车,1:月租车,2储值车，3军警车）
                        item.setCarNature(carEnterLog.getCarNature());
                        item.setCarTypeName(carEnterLog.getCarTypeName());

                        if (StringUtils.isEmpty(item.getCarTypeName()) && JddConstant.MqttRecResultPushLog.IS_WHITE_ZERO.equals(item.getCarNature())) {
                            item.setCarTypeName(JddConstant.VehicleType.TEMPORARYCAR);
                        }

                        ParkCarOutLog parkOutLog = parkCarOutLogService.getParkOutEnterLogByEnterId(item.getCarEnterId());
                        if (parkOutLog != null) {
                            //出场类型 1 : 正常出场 2：手动出场 3：补录场内
                            Integer outerType = parkOutLog.getOuterType();
                            item.setOuterType(outerType == null ? JddConstant.IntNumber.INT_ONE : outerType);
                            item.setOutTime(parkOutLog.getCarOutTime());
                            item.setArmName(parkOutLog.getArmName());
                            item.setWorkName(parkOutLog.getWorkName());
                            item.setSysUserName(parkOutLog.getSysUserName());
                        }
                    }

                }
            });
        }
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 新岗亭车辆缴费记录
     *
     * @param parkOrderInfo 查询入参
     * @param pageNo        页码
     * @param pageSize      每页条数
     * @param timeStart     收费开始时间
     * @param timeEnd       收费结束时间
     * @return 缴费记录列表
     */
    @AutoLog(value = "新岗亭车辆缴费记录-分页列表查询")
    @ApiOperation(value = "新岗亭车辆缴费记录-分页列表查询", notes = "新岗亭车辆缴费记录-分页列表查询")
    @GetMapping(value = "/parkCarChargeList")
    public Result<IPage<ParkOrderInfo>> parkCarChargeList(ParkOrderInfo parkOrderInfo,
                                                          @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                          @RequestParam(name = "timeStart", required = false) String timeStart,
                                                          @RequestParam(name = "timeEnd", required = false) String timeEnd) {
        Result<IPage<ParkOrderInfo>> result = new Result<>();

        LambdaQueryWrapper<ParkOrderInfo> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtils.isNotEmpty(parkOrderInfo)) {
            //车牌号
            if (StringUtils.isNotEmpty(parkOrderInfo.getPlateNo())) {
                queryWrapper.like(ParkOrderInfo::getPlateNo, parkOrderInfo.getPlateNo());
            }
            //支付类型
            if (StringUtils.isNotEmpty(parkOrderInfo.getPayType())) {
                queryWrapper.like(ParkOrderInfo::getPayType, parkOrderInfo.getPayType());
            }
            //操作员
            if (StringUtils.isNotEmpty(parkOrderInfo.getSysUserName())) {
                queryWrapper.eq(ParkOrderInfo::getSysUserName, parkOrderInfo.getSysUserName());
            }
        }
        //收费时间
        if (StringUtils.isNotEmpty(timeStart)) {
            timeStart = DateUtil.dateToString(DateUtil.string2Date(timeStart, "yyyy-MM-dd HH:mm:ss"), "yyyyMMddHHmmss");
            queryWrapper.ge(ParkOrderInfo::getPayTime, timeStart);
        }
        if (StringUtils.isNotEmpty(timeEnd)) {
            timeEnd = DateUtil.dateToString(DateUtil.string2Date(timeEnd, "yyyy-MM-dd HH:mm:ss"), "yyyyMMddHHmmss");
            queryWrapper.le(ParkOrderInfo::getPayTime, timeEnd);
        }
        queryWrapper.orderByDesc(ParkOrderInfo::getCreateTime);

        Page<ParkOrderInfo> page = new Page<>(pageNo, pageSize);
        IPage<ParkOrderInfo> pageList = parkOrderInfoService.page(page, queryWrapper);
        List<ParkOrderInfo> records = pageList.getRecords();
        if (null != records) {
            records.forEach(item -> {
                if (StringUtils.isNotEmpty(item.getCarEnterId())) {
                    ParkCarEnterLog carEnterLog = parkCarEnterLogService.getById(item.getCarEnterId());
                    if (carEnterLog != null) {
                        //车辆性质(0:临时车,1:月租车,2储值车，3军警车）
                        item.setCarNature(carEnterLog.getCarNature());
                        item.setCarTypeName(carEnterLog.getCarTypeName());
                        if (StringUtils.isEmpty(item.getCarTypeName()) && JddConstant.MqttRecResultPushLog.IS_WHITE_ZERO.equals(item.getCarNature())) {
                            item.setCarTypeName(JddConstant.VehicleType.TEMPORARYCAR);
                        }
                    }
                    ParkCarOutLog carOutLog = parkCarOutLogService.getParkOutEnterLogByEnterId(item.getCarEnterId());
                    if (carOutLog != null) {
                        item.setOutTime(carOutLog.getCarOutTime());
                        item.setArmName(carOutLog.getArmName());
                        item.setWorkName(carOutLog.getWorkName());
                        item.setSysUserName(carOutLog.getSysUserName());
                    }
                }
            });
        }
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 新岗亭车辆月租记录
     *
     * @param monthlyCardInfoDTO 查询入参
     * @param pageNo             页码
     * @param pageSize           每页条数
     * @param timeStart          到期开始时间
     * @param timeEnd            到期结束时间
     * @return 月租记录列表
     */
    @AutoLog(value = "新岗亭车辆月租记录-分页列表查询")
    @ApiOperation(value = "新岗亭车辆月租记录-分页列表查询", notes = "新岗亭车辆月租记录-分页列表查询")
    @GetMapping(value = "/monthlyCardList")
    public Result<IPage<MonthlyCardInfoDTO>> monthlyCardList(MonthlyCardInfoDTO monthlyCardInfoDTO,
                                                             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                             @RequestParam(name = "timeStart", required = false) String timeStart,
                                                             @RequestParam(name = "timeEnd", required = false) String timeEnd) {
        Result<IPage<MonthlyCardInfoDTO>> result = new Result<>();
        QueryWrapper<MonthlyCardInfoDTO> queryWrapper = new QueryWrapper<>();


        boolean needQueryWithCondition = StringUtils.isNotBlank(monthlyCardInfoDTO.getPackageId()) || StringUtils.isNotBlank(timeStart) || StringUtils.isNotBlank(timeEnd);

        QueryWrapper<MonthlyCardInfo> monthlyCardInfoQueryWrapper = new QueryWrapper<>();
        // 月租套餐
        if (StringUtils.isNotBlank(monthlyCardInfoDTO.getPackageId())) {
            monthlyCardInfoQueryWrapper.lambda().eq(MonthlyCardInfo::getPackageId, monthlyCardInfoDTO.getPackageId());
        }
        //月租状态
        if (ObjectUtils.isNotEmpty(monthlyCardInfoDTO.getMonthlyStatus())) {
            monthlyCardInfoQueryWrapper.lambda().eq(MonthlyCardInfo::getMonthlyStatus, monthlyCardInfoDTO.getMonthlyStatus());
        }
        // 到期时间匹配
        if (StringUtils.isNotBlank(timeStart)) {
            monthlyCardInfoQueryWrapper.ge("monthly_card_info.end_time", DateUtil.fomatDateTime(timeStart));
        }
        if (StringUtils.isNotBlank(timeEnd)) {
            monthlyCardInfoQueryWrapper.le("monthly_card_info.end_time", DateUtil.fomatDateTime(timeEnd));
        }

        if (needQueryWithCondition) {
            List<String> monthlyCardInfoIds = monthlyCardInfoService.getIds(monthlyCardInfoQueryWrapper).stream().distinct().collect(Collectors.toList());
            if (CollUtil.isEmpty(monthlyCardInfoIds)) {
                return result;
            } else {
                queryWrapper.in("monthly_card_info.id", monthlyCardInfoIds);
            }
        }

        // 车牌号模糊查询
        if (StringUtils.isNotBlank(monthlyCardInfoDTO.getPlateNo())) {
            QueryWrapper<ParkCarMonthly> plateNoQueryWrapper = new QueryWrapper<>();
            plateNoQueryWrapper.lambda().like(ParkCarMonthly::getPlateNo, monthlyCardInfoDTO.getPlateNo());
            List<String> monthlyCardInfoIds = parkCarMonthlyService.monthlyCarInfoIds(plateNoQueryWrapper).stream().distinct().collect(Collectors.toList());
            if (CollUtil.isEmpty(monthlyCardInfoIds)) {
                return result;
            } else {
                queryWrapper.in("monthly_card_info.id", monthlyCardInfoIds);
            }
        }

        Page<MonthlyCardInfoDTO> page = new Page<>(pageNo, pageSize);
        IPage<MonthlyCardInfoDTO> iPage = parkCarMonthlyService.monthlyCarInfoList(page, queryWrapper);
        iPage.setRecords(getMonthlyCardInfos(iPage));
        result.setResult(iPage);
        return result;
    }

    /**
     * 组装月租记录
     *
     * @param iPage 月卡信息
     * @return 月租记录列表
     */
    private List<MonthlyCardInfoDTO> getMonthlyCardInfos(IPage<MonthlyCardInfoDTO> iPage) {
        List<MonthlyCardInfoDTO> dealRecord = iPage.getRecords();
        if (CollectionUtils.isNotEmpty(dealRecord)) {
            int dayLin = 30;

            for (MonthlyCardInfoDTO monthlyCardInfo : dealRecord) {
                //正常
                monthlyCardInfo.setIsLay(JddConstant.StringNumber.STRING_THREE);
                //根据部门id查询当前部门的所有上级部门并拼接返回
                monthlyCardInfo.setMonthlyDepartmentName(monthlyDepartmentService.getDepartmentNameChain(monthlyCardInfo.getMonthlyDepartmentId()));

                //先判断是否过期，过期设为0
                if (System.currentTimeMillis() > monthlyCardInfo.getEndTime().getTime()) {
                    //过期
                    monthlyCardInfo.setIsLay(JddConstant.StringNumber.STRING_ZERO);
                } else {
                    MonthlyCarConfig monthlyCarConfig = monthlyCarConfigService.queryByParkCode(monthlyCardInfo.getParkCode()).getResult();
                    int days = DateUtil.differentDaysByMillisecond(new Date(), monthlyCardInfo.getEndTime());
                    if (monthlyCarConfig != null) {
                        dayLin = Integer.parseInt(monthlyCarConfig.getPeriodMonthlyDays());
                    }
                    if (days < dayLin) {
                        //临期
                        monthlyCardInfo.setIsLay(JddConstant.StringNumber.STRING_ONE);
                    }
                }
            }
        }
        return dealRecord;
    }

    /**
     * 新岗亭场内车辆信息
     *
     * @param inParkingCar 查询入参
     * @param pageNo       页码
     * @param pageSize     每页条数
     * @return 场内车辆信息列表
     */
    @AutoLog(value = "新岗亭场内车辆信息-分页列表查询")
    @ApiOperation(value = "新岗亭场内车辆信息-分页列表查询", notes = "新岗亭场内车辆信息-分页列表查询")
    @GetMapping(value = "/inParkingCarList")
    public Result<IPage<InParkinglotCar>> inParkingCarList(InParkinglotCar inParkingCar,
                                                           @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                           @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Result<IPage<InParkinglotCar>> result = new Result<>();
        LambdaQueryWrapper<InParkinglotCar> queryWrapper = new LambdaQueryWrapper<>();
        if (ObjectUtils.isNotEmpty(inParkingCar)) {
            if (StringUtils.isNotEmpty(inParkingCar.getPlateNo())) {
                queryWrapper.like(InParkinglotCar::getPlateNo, inParkingCar.getPlateNo());
            }
            if (StringUtils.isNotEmpty(inParkingCar.getCarType())) {
                queryWrapper.eq(InParkinglotCar::getCarType, inParkingCar.getCarType());
            }
            if (StringUtils.isNotEmpty(inParkingCar.getCarNature())) {
                queryWrapper.eq(InParkinglotCar::getCarNature, inParkingCar.getCarNature());
            }
        }
        queryWrapper.eq(InParkinglotCar::getIsOut, JddConstant.StringNumber.STRING_ZERO);
        queryWrapper.ne(InParkinglotCar::getIsTransfer, JddConstant.StringNumber.STRING_ONE);
        queryWrapper.orderByDesc(InParkinglotCar::getCreateTime);
        Page<InParkinglotCar> page = new Page<>(pageNo, pageSize);
        IPage<InParkinglotCar> pageList = parkCarInfoService.page(page, queryWrapper);
        List<InParkinglotCar> records = pageList.getRecords();
        if (null != records) {
            records.forEach(item -> {
                //车牌颜色
                String carTypeNo = item.getCarTypeNo();
                if (carTypeNo != null) {
                    item.setPcColor(CarColorEnum.getEnumByCode(carTypeNo).getColor());
                }
                //停车时长
                DateTime parse = cn.hutool.core.date.DateUtil.parse(item.getCarEnterTime(), "yyyy-MM-dd HH:mm:ss");
                int timeDiff = (int) DateUtils.timeDiff(parse, new Date());
                item.setParkDuration(DateUtils.turnDayHourMinuteString(String.valueOf(timeDiff)));
            });
        }
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

}
